package com.lihaozhe.service;

import com.lihaozhe.dto.SecUser;
import com.lihaozhe.mapper.SecUserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsPasswordService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 密码升级
 * @author 李昊哲
 * @version 1.0
 * 2021/12/8 下午1:20
 */
@Service
@RequiredArgsConstructor
public class UserPasswordService implements UserDetailsPasswordService {
    private final SecUserMapper userMapper;
    @Override
    @Transactional
    public UserDetails updatePassword(UserDetails user, String newPassword) {
        int i = userMapper.updatePassword(user.getUsername(), newPassword);
        if (i > 0){
            return userMapper.selectByUsername(user.getUsername());
        }
        return user;
    }
}